GRASS GIS 101
This notebook is a quick introduction to GRASS and Jupyter Notebooks.
import sys
v = sys.version_info
print(f"We are using Python {v.major}.{v.minor}.{v.micro}")
We are using Python 3.10.12
GRASS Project Setup
# import standard Python packages
import os
import subprocess
import json
from io import StringIO
from pathlib import Path
from IPython.display import IFrame
Setup GRASS environment
sys.path.append(
subprocess.check_output(["grass", "--config", "python_path"], text=True).strip()
)
# import GRASS GIS python packages
%reload_ext autoreload
%autoreload 2
import grass.script as gs
import grass.jupyter as gj
# create a temporary folder where to place our GRASS project
import tempfile
tempdir = tempfile.TemporaryDirectory()
Create a new GRASS project
gs.create_project(path=tempdir.name, name="foss4g2024", epsg="2817", overwrite=True)
# start GRASS in the recently created project
session = gj.init(Path(tempdir.name,"foss4g2024"))
# !ogrinfo "/vsizip//vsicurl/https://www.stlouis-mo.gov/data/upload/data-files/stl_boundary.zip" -al
# !ogrinfo /vsizip//vsicurl/https://www.stlouis-mo.gov/data/upload/data-files/streets.zip -al
Import data
City Boundary
gs.run_command("v.import",
input="/vsizip//vsicurl/https://www.stlouis-mo.gov/data/upload/data-files/stl_boundary.zip",
output="stl_boundary",
layer="stl_boundary",
snap=0.0001,
# epsg=8801
)
Streets
streets_url="/vsizip//vsicurl/https://www.stlouis-mo.gov/data/upload/data-files/streets.zip"
gs.run_command("v.import",
input=streets_url,
output="stl_streets",
layer="TgrGeoCd",
snap=0.0001,
# epsg=8801
)
map = gj.InteractiveMap(map_backend="folium")
map.add_vector("stl_boundary", fill_color="none", line_color="red")
# map.add_vector("stl_streets", line_color="grey")
map.add_layer_control()
map.show()